#coding:utf-8

from es_test_store import initEsTestStore
from es_test_store import initEsDataStore

import datetime


def copy(r):
    m = {}
    m['NAME'] = r['NAME']
    m['URL'] = r['URL']
    m['SOURCE'] = r['SOURCE']
    m['TITLE'] = r['TITLE']
    m['CONTENT'] = r['CONTENT']
    m['CUT_TITLE'] = r['CUT_TITLE']
    m['CUT_CONTENT'] = r['CUT_CONTENT']
    m['TIME'] = r['TIME']
    m['KEYWORD'] = r['KEYWORD']
    return m


def copy_test_data(st,et):
    es1 = initEsDataStore()
    es2 = initEsTestStore()
    
    res = es1.getByTime(st,et)
    print res

    res = es1.next(res['si'])

    while len(res['rs']) > 0:
        rs = res['rs']
        print len(rs)
        for r in rs:
            m = copy(r)
            es2.insert(m['NAME'],m)

        res = es1.next(res['si'])


if __name__ == '__main__':

    print 'Hi'

    T1 = datetime.datetime(2015,8,15)
    T2 = datetime.datetime(2015,8,16)

    copy_test_data(T1,T2)


